package com.ylxl.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ylxl.common.annotation.Log;
import com.ylxl.common.enums.BusinessType;
import com.ylxl.common.result.AjaxResult;
import com.ylxl.common.result.BaseController;
import com.ylxl.common.utils.StringUtils;
import com.ylxl.entity.ExceptionaLabor;
import com.ylxl.entity.ExceptionaLaborDetail;
import com.ylxl.entity.reponse.ExceptionaLaborVO;
import com.ylxl.entity.request.*;
import com.ylxl.service.IExceptionaLaborService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 例外劳保
 * @Auther Gilbert
 * @Date 2023/5/30 19:51
 */
@Slf4j
@RestController
@RequestMapping("/exceptionaLabor")
@Api(tags = "例外劳保", hidden = true)
public class ExceptionaLaborController extends BaseController {

    @Autowired
    private IExceptionaLaborService exceptionaLaborService;


    /**
     * 分页查询例外劳保
     * @param queryExceptionaLabor
     * @return
     */
    @Log(title = "分页查询例外劳保列表信息", businessType = BusinessType.SELECT)
    @PostMapping("/queryexceptionaLaborList")
    @ApiOperation(value = "分页查询例外劳保列表信息", response = AjaxResult.class)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ExceptionaLabor.class),})
    public AjaxResult queryProgramList(@RequestBody QueryExceptionaLabor queryExceptionaLabor) {
        AjaxResult ajax = AjaxResult.success();
        try {
            //进行分页操作
            PageInfo<ExceptionaLabor> pageInfo = new PageInfo<>();
            if (StringUtils.isNotEmpty(queryExceptionaLabor.getPageNum()) && StringUtils.isNotEmpty(queryExceptionaLabor.getPageSize())) {
                PageHelper.startPage(queryExceptionaLabor.getPageNum(), queryExceptionaLabor.getPageSize());
            }
            List<ExceptionaLabor> exceptionaLabors = exceptionaLaborService.selectLabelList(queryExceptionaLabor);
            pageInfo = new PageInfo<>(exceptionaLabors);
            ajax.put(AjaxResult.DATA_TAG, exceptionaLabors);
            ajax.put(AjaxResult.TOTAL, pageInfo.getTotal());
        } catch (Exception e) {
            log.error("查询例外劳保日志信息，异常信息：{}", e);
            return toAjax(false);
        }
        return ajax;
    }

    @Log(title = "例外劳保保存", businessType = BusinessType.INSERT)
    @PostMapping("/insert")
    @ApiOperation(value = "例外劳保保存", response = AjaxResult.class)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = Integer.class),})
    public AjaxResult add(@RequestBody ExceptionaLaborCmdOrMdy exceptionaLaborCmdOrMdy){
        return toAjax(exceptionaLaborService.insertExceptionaLabor(exceptionaLaborCmdOrMdy));
    }

    @Log(title = "例外劳保编辑", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ApiOperation(value = "节目编辑", response = AjaxResult.class)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = Integer.class),})
    public AjaxResult update(@RequestBody ExceptionaLaborCmdOrMdy exceptionaLaborCmdOrMdy){
        return toAjax(exceptionaLaborService.updateExceptionaLabor(exceptionaLaborCmdOrMdy));
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "例外劳保根据编号(id)查询明细", response = AjaxResult.class)
    @Log(title = "例外劳保根据编号(id)查询明细", businessType = BusinessType.SELECT)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ExceptionaLaborVO.class),})
    public AjaxResult getInfo(@PathVariable(value = "id", required = true) Integer id) {
        return AjaxResult.success(exceptionaLaborService.selctById(id));
    }


    @PostMapping("/remove")
    @ApiOperation(value = "例外劳保根据ids数组删除", response = AjaxResult.class)
    @Log(title = "例外劳保根据ids数组删除", businessType = BusinessType.DELETE)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = Integer.class),})
    public AjaxResult remove(@RequestBody DeleteRequest deleteRequest) {
        return AjaxResult.success(exceptionaLaborService.deleteByIds(deleteRequest.getIds()));
    }
    @GetMapping("/labor/{id}")
    @ApiOperation(value = "根据例外劳保(id)查询领取确认", response = AjaxResult.class)
    @Log(title = "根据例外劳保(id)查询领取确认", businessType = BusinessType.SELECT)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = ExceptionaLaborDetail.class),})
    public AjaxResult getLaoboDetailInfo(@PathVariable(value = "laborId", required = true) Integer laborId) {
        return AjaxResult.success(exceptionaLaborService.selctByDetailId(laborId));
    }
    /**
     * 例外劳保领取和不领取
     */
    @PostMapping("/enableOrDisable")
    @ApiOperation(value = "例外劳保领取和不领取", response = AjaxResult.class)
    @Log(title = "例外劳保领取和不领取", businessType = BusinessType.DELETE)
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = Integer.class),})
    public AjaxResult enableOrDisable(@RequestBody StatusRequest statusRequest) {
        return AjaxResult.success(exceptionaLaborService.enableOrDisable(statusRequest));
    }
}

